package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.yjhb.android.sbz.R;
import com.yjhb.android.sbz.entity.Follow;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;
import com.jojo.android.zxlib.tool.ZxTimeTool;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2020/11/19 9:48
 */
public class FollowAdapter extends BaseRecyclerAdapter<FollowAdapter.Holder, Follow> {
    private final String TAG = "FollowAdapter";
    private int type; //1关注2粉丝

    public FollowAdapter(Context context, int type) {
        super(context);
        this.type = type;
    }

    @Override
    protected Holder getHolder(View v) {
        return new Holder(v);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_follow;
    }

    @Override
    public void onBindViewHolder(@NonNull Holder holder, int i) {
        try {
            final int index = i;
            Follow entity = data.get(index);
            Glide.with(context).load(entity.getAvatar()).apply(new RequestOptions().placeholder(R.mipmap.test_head)).into(holder.headIv);
            if (type == 1) {
                holder.dateTv.setText(ZxTimeTool.getDate(entity.getFollowTime().getTime(), "yyyy-MM-dd"));
                holder.buttonTv.setVisibility(View.VISIBLE);
            } else if (type == 2) {
                holder.dateTv.setText(ZxTimeTool.getDate(entity.getSubscribeTime().getTime(), "yyyy-MM-dd"));
                holder.buttonTv.setVisibility(View.GONE);
            }
            holder.titleTv.setText(entity.getNickName());
            holder.buttonTv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (itemClickListener != null) {
                        itemClickListener.onViewClick(v, "关注", index, entity);
                    }
                }
            });
        } catch (Exception e) {
        }
    }


    class Holder extends RecyclerView.ViewHolder {
        @BindView(R.id.head_iv)
        ImageView headIv;
        @BindView(R.id.title_tv)
        TextView titleTv;
        @BindView(R.id.date_tv)
        TextView dateTv;
        @BindView(R.id.info_layout)
        LinearLayout infoLayout;
        @BindView(R.id.button_tv)
        TextView buttonTv;

        public Holder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
